$(function(){

    $("#bank").val(bank);

    city=city.split("/");
    //条件查询开始
    $("#distpicker1").distpicker({
        autoSelect: false,
        province: city[0],
        city: city[1],
        district: city[2],
    });

    //律师基本情况弹框开始
    $('.circumstances-btn').on('click',function(){
        $('#edit-circumstances').show();

    })


    //编辑律师信息保存
    $('.circumstances-save').on('click',function(){


        if(!$("#edit_lawyer").validate().form()){

            return;
        }

        var edit_lawyer = $("#edit_lawyer").serialize();

        var editCity={};


        $("#distpicker1").find("select option:selected").each(function(i,v){


                var k_v=$(v).attr("data-code")

                var v_v=$(v).val();

                editCity[k_v]=v_v;

        });


        Loading.show();



        $.ajax({
            type:"post",
            url:"/lawyer/updateLwayerInfoForInfo",
            data:edit_lawyer+"&editLawyer="+JSON.stringify(editCity) ,
            dataType: "json",
            success:function(data){

                if(data.code=="1"){

                    alert(data.msg);

                    $('#edit-circumstances').hide();

                    window.location.reload();

                }else{

                    alert(data.msg);

                }


                Loading.hide();

            },
            error:function(){
                alert("报错啦");
            }
        })





    })

    //编辑银行卡信息
    $('.circumstances-cancel').on('click',function(){

        $('#edit-circumstances').hide();
    })
    //律师基本情况弹框结束
    //律师标签设置开始
    $('.sign-btn').on('click',function(){
        $('#edit-sign').show();
    })

    //保存律师标签信息
    $('.sign-save').on('click',function(){
        //
        if(!$("#edit_lawyer_info").validate().form()){

            return;
        }


        Loading.show();

        var lawyer_id=$(this).attr("data-value");

        var editPlates = new Array();

        var addHonor = new Array();

        var editPrefer=new Array();

        var editAdvantage=new Array();


        $("input[name='edit_plate']:checked").each(function (m, n) {

            editPlates.push($(n).val());

        })

        $("input[name='edit_prefer']:checked").each(function (m, n) {

            editPrefer.push($(n).val());

        })


        $(".edit_advantage option:selected").each(function (m, n) {

            editAdvantage.push($(n).val());

        })


        var editHonor = {};

        $("input[name='edit_honor']").each(function (m, n) {


            var v_v = $(n).val();

            var k_v = $(n).attr("data-value");

            editHonor[k_v] = v_v;


        })



        $("input[name='add_honor']").each(function (m, n) {


            var val = $(n).val().trim();

            if (val != "") {

                addHonor.push(val);
            }


        });



        $.ajax({
            type: "post",
            url: "/lawyer/updateLwayerInfo",
            data: {
                editPrefer:editPrefer,
                editAdvantage:editAdvantage,
                editPlates: editPlates,
                addHonor: addHonor,
                editHonor: JSON.stringify(editHonor),
                lawyerId: lawyer_id
            },
            dataType: "json",
            success: function (data) {


                if (data.code == "1") {

                    alert(data.msg);

                    window.location.reload();

                } else {

                    alert(data.msg);

                }

                $('#edit-sign').hide();

                Loading.hide();

            },
            error: function () {
                alert("报错啦");
            }
        })



    })
    $('.sign-cancel').on('click',function(){
        $('#edit-sign').hide();
    })


    $('.state-right').on('click','.add-btn',function(){
        $(this).before($('<input type="text" name="add_honor" class="form-control required" maxlength="10"/>'))
    });
    //律师标签设置结束

    //律师工作经验编辑
    $('.experience-btn').on('click',function(){
        $('#edit-experience').show();
    })

    //保存律师工作经验
    $('.experience-save').on('click',function(){

        if(!$("#edit_workingExp").validate().form()){

            return;
        }
        var edit_workingExp = $("#edit_workingExp").serialize();

        Loading.show();

        $.ajax({
            type:"post",
            url:"/lawyer/updateLwayerInfoForInfo",
            data:edit_workingExp,
            dataType: "json",
            success:function(data){

                if(data.code=="1"){

                    alert(data.msg);

                    $('#edit-experience').hide();

                    window.location.reload();

                }else{

                    alert(data.msg);

                }


                Loading.hide();

            },
            error:function(){
                alert("报错啦");
            }
        })


    })
    $('.experience-cancel').on('click',function(){
        $('#edit-experience').hide();
    })
    //律师教育背景编辑
    $('.education-btn').on('click',function(){
        $('#edit-education').show();
    })

    //保存律师的教育背景
    $('.education-save').on('click',function(){

        if(!$("#edit_educationBack").validate().form()){

            return;
        }

        var edit_educationBack = $("#edit_educationBack").serialize();

        Loading.show();

        $.ajax({
            type:"post",
            url:"/lawyer/updateLwayerInfoForInfo",
            data:edit_educationBack,
            dataType: "json",
            success:function(data){

                if(data.code=="1"){

                    alert(data.msg);

                    $('#edit-education').hide();

                    window.location.reload();

                }else{

                    alert(data.msg);

                }


                Loading.hide();

            },
            error:function(){
                alert("报错啦");
            }
        })



    })
    $('.education-cancel').on('click',function(){
        $('#edit-education').hide();
    })
    //备注
    $('.remark-btn').on('click',function(){
        $('#edit-remark').show();
    })
    //保存备注信息
    $('.remark-save').on('click',function(){

        if(!$("#edit_sysBak").validate().form()){

            return;
        }

        var edit_sysBak = $("#edit_sysBak").serialize();

        Loading.show();

        $.ajax({
            type:"post",
            url:"/lawyer/updateLwayerInfoForInfo",
            data:edit_sysBak,
            dataType: "json",
            success:function(data){

                if(data.code=="1"){

                    alert(data.msg);

                    $('#edit-remark').hide();

                    window.location.reload();

                }else{

                    alert(data.msg);

                }


                Loading.hide();

            },
            error:function(){
                alert("报错啦");
            }
        })


    })
    $('.remark-cancel').on('click',function(){
        $('#edit-remark').hide();
    })
    //财务参数设定
    $('.financial-btn').on('click',function(){
        $('#edit-financial').show();
    })
    $('.financial-save').on('click',function(){
      //


        if(!$("#edit_financial").validate().form()){

            return;
        }

        $("#edit_hidden_tel_price").val($("#edit_tel_price").val()*100);

        $("#edit_hidden_pig_price").val($("#edit_pig_price").val()*100);


        var edit_financial = $("#edit_financial").serialize();

        Loading.show();

        $.ajax({
            type:"post",
            url:"/lawyer/updateLwayerInfoForInfo",
            data:edit_financial,
            dataType: "json",
            success:function(data){

                if(data.code=="1"){

                    alert(data.msg);

                    $('#edit-financial').hide();

                    window.location.reload();

                }else{

                    alert(data.msg);

                }


                Loading.hide();

            },
            error:function(){
                alert("报错啦");
            }
        })


    })
    $('.financial-cancel').on('click',function(){
        $('#edit-financial').hide();
    })
    //银行卡信息编辑
    //条件查询开始 edit-bank
    $("#distpicker2").distpicker({
        autoSelect: false
    });
    $('.bank-btn').on('click',function(){
        $('#edit-bank').show();
    })


    //银行卡信息保存
    $('.bank-save').on('click',function(){


        if(!$("#edit_bank").validate().form()){

            return;
        }


        var edit_bank = $("#edit_bank").serialize();

        Loading.show();

        $.ajax({
            type:"post",
            url:"/lawyer/updateLwayerInfoForInfo",
            data:edit_bank,
            dataType: "json",
            success:function(data){

                if(data.code=="1"){

                    alert(data.msg);

                    $('#edit-bank').hide();

                    window.location.reload();

                }else{

                    alert(data.msg);

                }


                Loading.hide();

            },
            error:function(){
                alert("报错啦");
            }
        })






    })
    $('.bank-cancel').on('click',function(){
        $('#edit-bank').hide();
    })





     var handler_money=back_money_handler(allMoney/100);

     var handler_allDistillMoney=back_money_handler(allDistillMoney/100);

     var handler_allTxMoney=back_money_handler(allTxMoney/100);

     var handler_telPrice= back_money_handler(telPrice/100);

     var handler_pigPrice=back_money_handler(pigPrice/100);


     $("#all_money").text(handler_money);

     $("#all_distill_money").text(handler_allDistillMoney);

     $("#all_tx_money").text(handler_allTxMoney);

     $("#tel_price").text(handler_telPrice);

     $("#pig_price").text(handler_pigPrice);


    $("#edit_tel_price").val(handler_telPrice);

    $("#edit_pig_price").val(handler_pigPrice);


    $("#edit_pig_price").keypress(function () {
        var reg = $(this).val().match(/\d+(\.\d{1,2})?/);
        var txt = '';
        if (reg != null)
        {
            txt = reg[0];
        }
        $(this).val(txt);
    }).change(function () {
        $(this).keypress();
    });


    $("#edit_tel_price").keypress(function () {
        var reg = $(this).val().match(/\d+(\.\d{1,2})?/);
        var txt = '';
        if (reg != null)
        {
            txt = reg[0];
        }
        $(this).val(txt);
    }).change(function () {
        $(this).keypress();
    });


})



